package com.cn.medicalcare.controller.backstageservlet.product;

import com.cn.medicalcare.customtool.JsonTool;
import com.cn.medicalcare.pojo.AllPage;
import com.cn.medicalcare.pojo.Page;
import com.cn.medicalcare.pojo.Product;
import com.cn.medicalcare.pojo.ProductInfo;
import com.cn.medicalcare.service.ProductInfoService;
import com.cn.medicalcare.service.ProductService;
import com.cn.medicalcare.service.serviceimpl.ProductInfoServiceImpl;
import com.cn.medicalcare.service.serviceimpl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

@WebServlet("/backstage/product/getproductinfobyproduct_id.json")
public class ProductInfoByProduct_idServlet extends HttpServlet {

    private ProductInfoService productInfoService = ProductInfoServiceImpl.getInstance();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, Object> map = new LinkedHashMap<>();
        try {
            map.put("status", 200);
            map.put("data", productInfoService.selectProductInfoByProduct_id(Integer.parseInt(req.getParameter("product_id"))));
        } catch (Exception e) {
            map.put("status", 500);
        }
        resp.getWriter().print(JsonTool.toJson(map));
    }
}
